//
//  ViewController.m
//  demo36图片拼接
//
//  Created by bing on 16/1/6.
//  Copyright © 2016年 bing. All rights reserved.
//

#import "ViewController.h"
#import "BYImageHelper.h"

@interface ViewController ()
@property (nonatomic, strong) BYMergeInfo *info;
@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
static NSInteger count = 0;
- (IBAction)methon1:(id)sender {
    NSString *file11 = [[NSBundle mainBundle] pathForResource:@"img1" ofType:@"png"];
    UIImage *top     = [UIImage imageWithContentsOfFile:file11];
    NSString *file12 = [[NSBundle mainBundle] pathForResource:@"img2" ofType:@"png"];
    UIImage *down    = [UIImage imageWithContentsOfFile:file12];
    
    UInt64 time1 = [[NSDate date] timeIntervalSince1970] * 1000;
    for (int i = 0; i < 100; i++) {
        _info = [BYImageHelper computeMethod1MergeInfoWithTopImage:top downImage:down];
    }
    UInt64 time2 = [[NSDate date] timeIntervalSince1970] * 1000;
    NSLog(@"---%llu---", time2 - time1);
    
    
    UIImage *img = [BYImageHelper stitchingImageWithInfo:_info];
    NSData *data = UIImagePNGRepresentation(img);
    NSString *file = [NSString stringWithFormat:@"/Users/bing/Desktop/img%ld.png", (long)count];
    [data writeToFile:file atomically:YES];
}
- (IBAction)methon2:(id)sender {
    NSString *file11 = [[NSBundle mainBundle] pathForResource:@"img1" ofType:@"png"];
    UIImage *top     = [UIImage imageWithContentsOfFile:file11];
    NSString *file12 = [[NSBundle mainBundle] pathForResource:@"img2" ofType:@"png"];
    UIImage *down    = [UIImage imageWithContentsOfFile:file12];
    
    UInt64 time1 = [[NSDate date] timeIntervalSince1970] * 1000;
    for (int i = 0; i < 100; i++) {
        _info = [BYImageHelper computeMethod2MergeInfoWithTopImage:top downImage:down];
    }
    UInt64 time2 = [[NSDate date] timeIntervalSince1970] * 1000;
    NSLog(@"---%llu---", time2 - time1);
    
    
    UIImage *img = [BYImageHelper stitchingImageWithInfo:_info];
    NSData *data = UIImagePNGRepresentation(img);
    NSString *file = [NSString stringWithFormat:@"/Users/bing/Desktop/img%ld.png", (long)count];
    [data writeToFile:file atomically:YES];
}
@end
